﻿using System;
using System.Collections.Generic;
using System.Text;

namespace gsl_runtime_sdk
{
    public class PHPCompiler
    {
        public List<Variable> Variable = new List<Variable>();
        public List<string> names = new List<string>();
        
        public static string ToPHP(string GSL)
        {
            //string[] scpcode = scode.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            return GSL;
        }
        public static string[] FromPHP(string PHP)
        {
            List<string> names = new List<string>();
            List<string> GSL = new List<string>();
            string[] scode = PHP.Split(new char[1] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string str in scode)
            {
                string[] scpcode = str.Split(new char[2] { '(', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (scpcode[0].Substring(0,0) == "$")
                {
                    if (names.Contains(scpcode[0]))
                    {
                        GSL.Add(scpcode[0].Substring(1) + " " + scpcode[1] + (scpcode.Length - 1 >= 2 ? " " + scpcode[2] + ";" : ";"));
                    }
                    else
                    {
                        if (scpcode.Length - 1 > 2)
                        {
                            GSL.Add("var " + scpcode[0].Substring(1) + " = " + (scpcode[2].Substring(0,0) == "$" ? scpcode[2].Substring(1) : scpcode[2]));
                        }
                        else
                            GSL.Add("var " + scpcode[0].Substring(1));
                    }
                }
                switch (scpcode[0])
                {

                }
            }
            return GSL.ToArray();
        }
        public static string ToGSL(string PHP)
        {
            return PHP;
        }
    }
}
